package com.ruoyi.animal.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.animal.mapper.AnimalSpeciesMapper;
import com.ruoyi.animal.domain.AnimalSpecies;
import com.ruoyi.animal.service.IAnimalSpeciesService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 动物类型Service业务层处理
 * 
 * @author gw
 * @date 2025-01-06
 */
@Service
public class AnimalSpeciesServiceImpl implements IAnimalSpeciesService 
{
    @Autowired
    private AnimalSpeciesMapper animalSpeciesMapper;

    /**
     * 查询动物类型
     * 
     * @param speciesId 动物类型主键
     * @return 动物类型
     */
    @Override
    public AnimalSpecies selectAnimalSpeciesBySpeciesId(Long speciesId)
    {
        return animalSpeciesMapper.selectAnimalSpeciesBySpeciesId(speciesId);
    }

    /**
     * 查询动物类型列表
     * 
     * @param animalSpecies 动物类型
     * @return 动物类型
     */
    @Override
    public List<AnimalSpecies> selectAnimalSpeciesList(AnimalSpecies animalSpecies)
    {
        return animalSpeciesMapper.selectAnimalSpeciesList(animalSpecies);
    }

    /**
     * 新增动物类型
     * 
     * @param animalSpecies 动物类型
     * @return 结果
     */
    @Override
    public int insertAnimalSpecies(AnimalSpecies animalSpecies)
    {
        animalSpecies.setCreateTime(DateUtils.getNowDate());
        animalSpecies.setCreateBy(SecurityUtils.getUsername());
        return animalSpeciesMapper.insertAnimalSpecies(animalSpecies);
    }

    /**
     * 修改动物类型
     * 
     * @param animalSpecies 动物类型
     * @return 结果
     */
    @Override
    public int updateAnimalSpecies(AnimalSpecies animalSpecies)
    {
        animalSpecies.setUpdateTime(DateUtils.getNowDate());
        animalSpecies.setUpdateBy(SecurityUtils.getUsername());
        return animalSpeciesMapper.updateAnimalSpecies(animalSpecies);
    }

    /**
     * 批量删除动物类型
     * 
     * @param speciesIds 需要删除的动物类型主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteAnimalSpeciesBySpeciesIds(Long[] speciesIds)
    {
        int deletedCount = 0;
        for (Long speciesId : speciesIds) {
            AnimalSpecies animalSpecies = animalSpeciesMapper.selectAnimalSpeciesBySpeciesId(speciesId);
            animalSpecies.setDeleteBy(SecurityUtils.getUsername());
            animalSpecies.setDeleteTime(DateUtils.getNowDate());
            animalSpecies.setDelFlag(1);
            animalSpeciesMapper.updateAnimalSpecies(animalSpecies);
            deletedCount++;
        }
        return deletedCount;
    }

    /**
     * 删除动物类型信息
     * 
     * @param speciesId 动物类型主键
     * @return 结果
     */
    @Override
    public int deleteAnimalSpeciesBySpeciesId(Long speciesId)
    {
        AnimalSpecies animalSpecies = animalSpeciesMapper.selectAnimalSpeciesBySpeciesId(speciesId);
        animalSpecies.setDeleteBy(SecurityUtils.getUsername());
        animalSpecies.setDeleteTime(DateUtils.getNowDate());
        animalSpecies.setDelFlag(1);
        return animalSpeciesMapper.updateAnimalSpecies(animalSpecies);
    }
}
